#ifndef MQTTCLIENT_HEAD_H
#define MQTTCLIENT_HEAD_H
#include <iostream>
#include <mosquitto.h>
#include <string.h>
#include <errno.h>
//条件变量
#include <condition_variable>
#include <queue>
#include "MQTTMessage.h"

using namespace std;

class MQTTClient
{
public:
	MQTTClient(const string &pubTopic, const string &subTopic, int qos);
	~MQTTClient();
	bool        connect(const string &ip, uint16_t port);
	bool        disconnect(void);
	int         send(const void *data, uint32_t len);
	int         recv(void *data, uint32_t len);
	static void message(mosquitto *, void *obj, const mosquitto_message *msg);
	void        wait(void);
	void        notify(void);

private:
	string             pubTopic;
	string             subTopic;
	int                qos;
	struct mosquitto * mos;
	mutex              mtx;
	mutex              qmumtx; //队列的锁
	condition_variable cv;
	queue<MQTTMessage> msgQueue;
};

#endif